package com.longcai.piaojia.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.HomeGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2015/6/1.
 */
public class IndexNumGridAdapter extends ArrayAdapter<HomeGet.HomeClassifyEntity> {

    private LayoutInflater layoutInflater;
    private Context context;

    public HashMap<Integer, Boolean> isChecked = new HashMap<>();

    private List<HomeGet.Classify> objects;

    public IndexNumGridAdapter(Context context, List<HomeGet.HomeClassifyEntity> objects) {

        super(context, 0, objects);

        this.context = context;


        layoutInflater = ((Activity) context).getLayoutInflater();

    }

    public void initCheckFalse(List<HomeGet.Classify> objects, int pos) {

        for (int i = 0; i < objects.size(); i++) {

            if (i == pos) {

                isChecked.put(i, true);

            } else {

                isChecked.put(i, false);

            }

        }
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        HomeGet.HomeClassifyEntity numEntity = getItem(position);

        if (convertView == null) {

            //  convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_index_grid, null)));

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_index_grid, null)));


            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }


        viewHolder.text_chuchang.setText(numEntity.title);
        //  GlideLoader.getInstance().get(getActivity(), s, mine_head_icon_iv, R.mipmap.mine_headimg, GlideLoader.TYPE_IMAGE_CIRCLE);
//`
        GlideLoader.getInstance().get(context, numEntity.picurl, viewHolder.img_icon);
        return convertView;

    }

    private class ViewHolder {

        @BoundView(R.id.text_chuchang)
        public TextView text_chuchang;

        @BoundView(R.id.img_icon)
        public ImageView img_icon;

    }

}
